<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>relativewithplurals.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_date_relativewithplurals.js.html">relativewithplurals.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Code to make goog.date.relative plurals-aware.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>goog.provide(&#39;goog.date.relativeWithPlurals&#39;);
<a name="line20"></a>
<a name="line21"></a>goog.require(&#39;goog.date.relative&#39;);
<a name="line22"></a>goog.require(&#39;goog.date.relative.Unit&#39;);
<a name="line23"></a>goog.require(&#39;goog.i18n.MessageFormat&#39;);
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>/**
<a name="line27"></a> * Gets a localized relative date string for a given delta and unit.
<a name="line28"></a> * @param {number} delta Number of minutes/hours/days.
<a name="line29"></a> * @param {boolean} future Whether the delta is in the future.
<a name="line30"></a> * @param {goog.date.relative.Unit} unit The units the delta is in.
<a name="line31"></a> * @return {string} The message.
<a name="line32"></a> * @private
<a name="line33"></a> */
<a name="line34"></a>goog.date.relativeWithPlurals.formatTimeDelta_ =
<a name="line35"></a>    function(delta, future, unit) {
<a name="line36"></a>  if (!future &amp;&amp; unit == goog.date.relative.Unit.MINUTES) {
<a name="line37"></a>    /**
<a name="line38"></a>     * @desc Relative date indicating how many minutes ago something happened.
<a name="line39"></a>     */
<a name="line40"></a>    var MSG_MINUTES_AGO_ICU =
<a name="line41"></a>        goog.getMsg(&#39;{NUM, plural, &#39; +
<a name="line42"></a>            &#39;=0 {# minutes ago}&#39; +
<a name="line43"></a>            &#39;=1 {# minute ago}&#39; +
<a name="line44"></a>            &#39;other {# minutes ago}}&#39;);
<a name="line45"></a>
<a name="line46"></a>    return new goog.i18n.MessageFormat(MSG_MINUTES_AGO_ICU).
<a name="line47"></a>        format({&#39;NUM&#39;: delta});
<a name="line48"></a>
<a name="line49"></a>  } else if (future &amp;&amp; unit == goog.date.relative.Unit.MINUTES) {
<a name="line50"></a>    /**
<a name="line51"></a>     * @desc Relative date indicating in how many minutes something happens.
<a name="line52"></a>     */
<a name="line53"></a>    var MSG_IN_MINUTES_ICU =
<a name="line54"></a>        goog.getMsg(&#39;{NUM, plural, &#39; +
<a name="line55"></a>            &#39;=0 {in # minutes}&#39; +
<a name="line56"></a>            &#39;=1 {in # minute}&#39; +
<a name="line57"></a>            &#39;other {in # minutes}}&#39;);
<a name="line58"></a>
<a name="line59"></a>    return new goog.i18n.MessageFormat(MSG_IN_MINUTES_ICU).
<a name="line60"></a>        format({&#39;NUM&#39;: delta});
<a name="line61"></a>
<a name="line62"></a>  } else if (!future &amp;&amp; unit == goog.date.relative.Unit.HOURS) {
<a name="line63"></a>    /**
<a name="line64"></a>     * @desc Relative date indicating how many hours ago something happened.
<a name="line65"></a>     */
<a name="line66"></a>    var MSG_HOURS_AGO_ICU =
<a name="line67"></a>        goog.getMsg(&#39;{NUM, plural, &#39; +
<a name="line68"></a>            &#39;=0 {# hours ago}&#39; +
<a name="line69"></a>            &#39;=1 {# hour ago}&#39; +
<a name="line70"></a>            &#39;other {# hours ago}}&#39;);
<a name="line71"></a>
<a name="line72"></a>    return new goog.i18n.MessageFormat(MSG_HOURS_AGO_ICU).
<a name="line73"></a>        format({&#39;NUM&#39;: delta});
<a name="line74"></a>
<a name="line75"></a>  } else if (future &amp;&amp; unit == goog.date.relative.Unit.HOURS) {
<a name="line76"></a>    /**
<a name="line77"></a>     * @desc Relative date indicating in how many hours something happens.
<a name="line78"></a>     */
<a name="line79"></a>    var MSG_IN_HOURS_ICU =
<a name="line80"></a>        goog.getMsg(&#39;{NUM, plural, &#39; +
<a name="line81"></a>            &#39;=0 {in # hours}&#39; +
<a name="line82"></a>            &#39;=1 {in # hour}&#39; +
<a name="line83"></a>            &#39;other {in # hours}}&#39;);
<a name="line84"></a>
<a name="line85"></a>    return new goog.i18n.MessageFormat(MSG_IN_HOURS_ICU).
<a name="line86"></a>        format({&#39;NUM&#39;: delta});
<a name="line87"></a>
<a name="line88"></a>  } else if (!future &amp;&amp; unit == goog.date.relative.Unit.DAYS) {
<a name="line89"></a>    /**
<a name="line90"></a>     * @desc Relative date indicating how many days ago something happened.
<a name="line91"></a>     */
<a name="line92"></a>    var MSG_DAYS_AGO_ICU =
<a name="line93"></a>        goog.getMsg(&#39;{NUM, plural, &#39; +
<a name="line94"></a>            &#39;=0 {# days ago}&#39; +
<a name="line95"></a>            &#39;=1 {# day ago}&#39; +
<a name="line96"></a>            &#39;other {# days ago}}&#39;);
<a name="line97"></a>
<a name="line98"></a>    return new goog.i18n.MessageFormat(MSG_DAYS_AGO_ICU).
<a name="line99"></a>        format({&#39;NUM&#39;: delta});
<a name="line100"></a>
<a name="line101"></a>  } else if (future &amp;&amp; unit == goog.date.relative.Unit.DAYS) {
<a name="line102"></a>    /**
<a name="line103"></a>     * @desc Relative date indicating in how many days something happens.
<a name="line104"></a>     */
<a name="line105"></a>    var MSG_IN_DAYS_ICU =
<a name="line106"></a>        goog.getMsg(&#39;{NUM, plural, &#39; +
<a name="line107"></a>            &#39;=0 {in # days}&#39; +
<a name="line108"></a>            &#39;=1 {in # day}&#39; +
<a name="line109"></a>            &#39;other {in # days}}&#39;);
<a name="line110"></a>
<a name="line111"></a>    return new goog.i18n.MessageFormat(MSG_IN_DAYS_ICU).
<a name="line112"></a>        format({&#39;NUM&#39;: delta});
<a name="line113"></a>
<a name="line114"></a>  } else {
<a name="line115"></a>    return &#39;&#39;;
<a name="line116"></a>  }
<a name="line117"></a>};
<a name="line118"></a>
<a name="line119"></a>goog.date.relative.setTimeDeltaFormatter(
<a name="line120"></a>    goog.date.relativeWithPlurals.formatTimeDelta_);
</pre>


</body>
</html>
